package org.se.lab;

import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


public class User {
	
	private int id;
	private String username;
	private String password;
	private static final Logger logger = LoggerFactory.getLogger(User.class);


	public User(int id, String username, String password) {
		setId(id);
		setPassword(password);
		setUsername(username);
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		if (id < 0)
			throw new IllegalArgumentException();
		this.id = id;
		logger.info("Id = "+ id);
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		if (username == null)
			throw new IllegalArgumentException();
		this.username = username;
		logger.info("Username = "+username);
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		if (password == null)
			throw new IllegalArgumentException();
		this.password = password;
		logger.info("Password = "+ password);
	}

	/*
	 * Association with User[0..*]
	 */

	private List<Mail> mails = new ArrayList<Mail>();

	public void addMail(Mail mail) {
		if (mail == null)
			throw new IllegalArgumentException();
		mails.add(mail);
	}

	public List<Mail> getMails() {
		return mails;
	}

	public void setMails(List<Mail> mails) {
		if (mails == null)
			throw new IllegalArgumentException();
		this.mails = mails;
		logger.info("MailList = "+ mails.size());
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + id;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		User other = (User) obj;
		if (id != other.id)
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "User [id=" + id + ", username=" + username + ", password="
				+ password + "]";
	}

}
